<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/30 0030
 * Time: 14:17
 */
//php四种链接文件的方式
//@ 非必要报错信息屏蔽  比如说警告信息屏蔽
//1.include 文件路径     加载
//include "publics.php";
//2.include_once  只加载一次 使用方式同include
//include_once 'publics.php';
//3.require 使用方法同include
//require 'publics.php';
//4.require_once    只加载一次。使用方式同上
//区别
require_once 'publics.php';
//注册
//注册一个账号，和自定义密码
if(!empty($_POST)){
    $username = $_POST['username'];
    $password = $_POST['password'];
    $sql1 = "select username from user where  username = '".$username."'";
    $res = query($sql1);
    if(empty($res)){
        $sql = "insert into user (username,password) VALUES ('".$username."','".$password."')";
        $user = insert($sql);
        if($user == true){
            echo '<script type="text/javascript">';
//        echo 'alert("注册成功！");';
            echo 'window.location.href = "https://www.baidu.com/" ';
            echo '</script>';
        }else{
            echo '<script type="text/javascript">';
            echo 'window.location.href = "shibai.php" ';
//        echo 'alert("注册失败！");';
            echo '</script>';
        }
    }else{
        echo '<script type="text/javascript">';
        echo 'window.location.href = "/php28/reseter.php" ';
//        echo 'alert("注册失败！");';
        echo '</script>';
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <script src="jquery-1.10.1.min.js"></script>
</head>
<style type="text/css">
    .all{
        width: 100%;
        height: 940px;
    }
    .tij{
        width: 300px;
        height: 50px;
        margin-top: 27px;
    }
    #tij{
        width: 350px;
    }
    .nest_all{
        position: fixed;
        left: 35%;
        top: 31%;
        vertical-align: middle;
        width:366px ;
        height: 278px;
    }

</style>
<body>
<div class="all">
    <div class="nest_all">
<!--        <form action="reseter.php" method="post" onsubmit="return chekFrom()">-->
        <form action="reseter.php" method="post">
            账号：<input class="tij" type="text" name="username" id="username" value="" placeholder="请输入你的账号">
            <br>
            密码：<input class="tij" type="text" name="password" id="password" value="">
            <br>
            确认：<input class="tij" id="repassword" type="text" name="repassword"  value="" >
            <input type="submit" id="tij"  value="注册" class="tij" onclick="return chekFrom()">
        </form>
    </div>
</div>
<script type="text/javascript">
    function chekFrom(){
        var password = $("#password").val();
        var repassword = $("#repassword").val();
        if(password != repassword){
            alert("你输入的密码和确认密码不一样！请重新输入");
            return false;
        }
    }
</script>
</body>
</html>
